document.write("<p class='hs'>" + '考试系统哦' + "</p>")
//写cookie
function wcook(name, value) {
    var d = new Date();
    d.setHours(d.getHours() + (24 * 30));
    document.cookie = name + "=" + value + ";expires=" + d.toGMTString();
}
//读cookie
function rcook(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return (arr[2]);
    else
        return null;
}
//判断是否能做题
/*
function op() {
    var val = rcook('mark');
    var val1 = rcook('name');
    if ((val != null || val == '' || val.length == 0) && val1 == nam1) {
        document.getElementById("to").innerHTML = val1 + "&emsp;分数：" + val;
        document.getElementById("bt1").disabled = true;
        document.getElementById("bt2").disabled = true;
    }
}
*/
var count;
window.onload = function () {

    document.getElementById("nam").focus();
    count = rcook('kaoshicisua');
    count++;
    //document.getElementById("ci").innerHTML = "你是本设备第" + count + "位考试的" + "(没有数据库只能计算本设备考的咯)";
    Tim();
    display();
}
//系统时间
function Tim() {
    var oDate = new Date(); //实例一个时间对象；
    var mY = oDate.getFullYear();   //获取系统的年；
    var mMo = oDate.getMonth() + 1;   //获取系统月份，由于月份是从0开始计算，所以要加1
    var mD = oDate.getDate(); // 获取系统日，
    var mH = oDate.getHours(); //获取系统时，
    var mMi = oDate.getMinutes(); //分
    var mS = oDate.getSeconds(); //秒 
    if (mS < 10) {
        mS = "0" + mS;
    }
    if (mMi < 10) {
        mMi = "0" + mMi;
    }
    if (mH < 10) {
        mH = "0" + mH;
    }
    document.getElementById("ci").innerHTML = "欢迎登录考试系统" + "  当前时间：" + mY + "年" + mMo + "月" + mD + "日" + mH + "时" + mMi + "分" + mS + "秒";
    setTimeout('Tim()', 1000);
}

var it;
//提交判断
function cs() {
    var tol;
    var a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
    var rw1 = '√', rw2 = '√', rw3 = '√', rw4 = '√', rw5 = '√', rw6 = '√', rw7 = '√', rw8 = '√', rw9 = '√', rw10 = '√';
    var m = document.getElementById("num1").value;
    var n = document.getElementById("num2").value;
    var n3 = document.getElementById("num3").value;
    var n4 = document.getElementById("num4").value;
    var n5 = document.getElementById("num5").value;
    var n6 = document.getElementById("num6").value;
    var n7 = document.getElementById("num7").value;
    var n8 = document.getElementById("num8").value;
    var n9 = document.getElementById("num9").value;
    var n10 = document.getElementById("num10").value;
    if (m == answer1) {
        a1 = 10;
    } else {
        a1 = 0;
    }
    if (n == answer2) {
        a2 = 10;
    } else {
        a2 = 0;
    }
    if (n3 == aval3) {
        a3 = 10;
    } else {
        a3 = 0;
    }
    if (n4 == aval4) {
        a4 = 10;
    } else {
        a4 = 0;
    }
    if (n5 == aval5) {
        a5 = 10;
    } else {
        a5 = 0;
    }
    if (n6 == aval6) {
        a6 = 10;
    } else {
        a6 = 0;
    }
    if (n7 == aval7 ) {
        a7 = 10;
    } else {
        a7 = 0;
    }
    if (n8 == aval8 ) {
        a8 = 10;
    } else {
        a8 = 0;
    }
    if (n9 == aval9 ) {
        a9 = 10;
    } else {
        a9 = 0;
    }
    if (n10 == aval10 ) {
        a10 = 10;
    } else {
        a10 = 0;
    }
    tol = Number(a1) + Number(a2) + Number(a3) + Number(a4) + Number(a5) + Number(a6) + Number(a7) + Number(a8) + Number(a9) + Number(a10);
    document.getElementById("to").innerHTML = nam1 + "&emsp;分数：" + tol;
    if (a1 == 0) {
        rw1 = "×"
    }
    if (a2 == 0) {
        rw2 = "×"
    }
    if (a3 == 0) {
        rw3 = "×"
    }
    if (a4 == 0) {
        rw4 = "×"
    }
    if (a5 == 0) {
        rw5 = "×"
    }
    if (a6 == 0) {
        rw6 = "×"
    }
    if (a7 == 0) {
        rw7 = "×"
    }
    if (a8 == 0) {
        rw8 = "×"
    }
    if (a9 == 0) {
        rw9 = "×"
    }
    if (a10 == 0) {
        rw10 = "×"
    }
    document.getElementById("torw").innerHTML = "一、" + rw1 + ";" + rw2 + "二、" + rw3 + ";" + rw4 + "三、" + rw5 + ";" + rw6 + "四、" + rw7 + ";" + rw8 + "五、" + rw9 + ";" + rw10;
    document.getElementById("num1").disabled = true;
    document.getElementById("num2").disabled = true;
    document.getElementById("num3").disabled = true;
    document.getElementById("num4").disabled = true;
    document.getElementById("num5").disabled = true;
    document.getElementById("num6").disabled = true;
    document.getElementById("num7").disabled = true;
    document.getElementById("num8").disabled = true;
    document.getElementById("num9").disabled = true;
    document.getElementById("num10").disabled = true;
    document.getElementById("bt2").disabled = true;
    wcook(nam1, tol);
    wcook('kaoshicisua', count);
    clearInterval(it);
}
//做题的时间
var hour = 0, min = 3, i = 20;
function clink() {
    var tol;
    var a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
    var rw1 = '√', rw2 = '√', rw3 = '√', rw4 = '√', rw5 = '√', rw6 = '√', rw7 = '√', rw8 = '√', rw9 = '√', rw10 = '√';
    var so, mo, ho;
    if (i < 10) {
        so = "0" + i;
    } else {
        so = i;
    }
    if (min < 10) {
        mo = "0" + min;
    } else {
        mo = min;
    }
    if (hour < 10) {
        ho = "0" + hour;
    } else {
        ho = hour;
    }

    document.getElementById("ti").innerHTML = "剩余时间：" + ho + " 时 " + mo + " 分 " + so + " 秒";

    i--;
    if (i < 0) {
        i = 59;
        min--;
        if (min < 0) {
            min = 59;
            hour--;
        }
    }
    if (ho == 0 && mo == 0 && so == 0) {

        var m = document.getElementById("num1").value;
        var n = document.getElementById("num2").value;
        var n3 = document.getElementById("num3").value;
        var n4 = document.getElementById("num4").value;
        var n5 = document.getElementById("num5").value;
        var n6 = document.getElementById("num6").value;
        var n7 = document.getElementById("num7").value;
        var n8 = document.getElementById("num8").value;
        var n9 = document.getElementById("num9").value;
        var n10 = document.getElementById("num10").value;
        if (m == answer1) {
            a1 = 10;
        } else {
            a1 = 0;
        }
        if (n == answer2) {
            a2 = 10;
        } else {
            a2 = 0;
        }
        if (n3 == aval3) {
            a3 = 10;
        } else {
            a3 = 0;
        }
        if (n4 == aval4) {
            a4 = 10;
        } else {
            a4 = 0;
        }
        if (n5 == aval5) {
            a5 = 10;
        } else {
            a5 = 0;
        }
        if (n6 == aval6) {
            a6 = 10;
        } else {
            a6 = 0;
        }
        if (n7 == aval7 ) {
            a7 = 10;
        } else {
            a7 = 0;
        }
        if (n8 == aval8 ) {
            a8 = 10;
        } else {
            a8 = 0;
        }
        if (n9 == aval9 ) {
            a9 = 10;
        } else {
            a9 = 0;
        }
        if (n10 == aval10 ) {
            a10 = 10;
        } else {
            a10 = 0;
        }
        tol = Number(a1) + Number(a2) + Number(a3) + Number(a4) + Number(a5) + Number(a6) + Number(a7) + Number(a8) + Number(a9) + Number(a10);
        document.getElementById("to").innerHTML = nam1 + "&emsp;分数：" + tol;
        if (a1 == 0) {
            rw1 = "×"
        }
        if (a2 == 0) {
            rw2 = "×"
        }
        if (a3 == 0) {
            rw3 = "×"
        }
        if (a4 == 0) {
            rw4 = "×"
        }
        if (a5 == 0) {
            rw5 = "×"
        }
        if (a6 == 0) {
            rw6 = "×"
        }
        if (a7 == 0) {
            rw7 = "×"
        }
        if (a8 == 0) {
            rw8 = "×"
        }
        if (a9 == 0) {
            rw9 = "×"
        }
        if (a10 == 0) {
            rw10 = "×"
        }
        document.getElementById("torw").innerHTML = "一、" + rw1 + ";" + rw2 + "二、" + rw3 + ";" + rw4 + "三、" + rw5 + ";" + rw6 + "四、" + rw7 + ";" + rw8 + "五、" + rw9 + ";" + rw10;
        document.getElementById("num1").disabled = true;
        document.getElementById("num2").disabled = true;
        document.getElementById("num3").disabled = true;
        document.getElementById("num4").disabled = true;
        document.getElementById("num5").disabled = true;
        document.getElementById("num6").disabled = true;
        document.getElementById("num7").disabled = true;
        document.getElementById("num8").disabled = true;
        document.getElementById("num9").disabled = true;
        document.getElementById("num10").disabled = true;
        document.getElementById("bt2").disabled = true;
        wcook(nam1, tol);
        wcook('kaoshicisua', count);
        clearInterval(it);

        alert("时间到，答题结束了！");
        //showModelessDialog("时间还剩30秒！","dialogWidth:40px;dialogHeight:10px;");
    }
}
//题库
var aval3, aval4, aval5, aval6, aval7,  aval8, aval9, aval10,j=0;
var qu3=[],aw3=[],qu4=[],aw4=[],qu5=[],aw5=[],qu6=[],aw6=[],qu7=[],aw7=[],qu8=[],aw8=[],qu9=[],aw9=[],qu10=[],aw10=[];

function display()
{
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function(){
xmlDoc=xmlhttp.responseXML; 
 x=xmlDoc.getElementsByTagName("question");
qbank(qu3,aw3,0);
qbank(qu4,aw4,5);
qbank(qu5,aw5,10);
qbank(qu6,aw6,15);
qbank(qu7,aw7,20);
qbank(qu8,aw8,25);
qbank(qu9,aw9,30);
qbank(qu10,aw10,35);
}
xmlhttp.open("GET","questionbank.xml",true);
xmlhttp.send();
}

function qbank(q,a,num){
for(j=0;j<5;j++){
 q[j]=x[num].getElementsByTagName("description")[0].childNodes[0].nodeValue;
 a[j]=x[num].getElementsByTagName("answer")[0].childNodes[0].nodeValue;
 num++;
} 
}

function qn() {
   
    var rval3 = Math.floor(Math.random() * (qu3.length));
    var qval3 = qu3[rval3];
    aval3 = aw3[rval3];
    var put3 = '<input type="text" id="num3" name="num3" ></input>';
    document.getElementById("p3").innerHTML = qval3 + " 答：";
    document.getElementById("p3").innerHTML += put3;

    var rval4 = Math.floor(Math.random() * (qu4.length));
    var qval4 = qu4[rval4];
    aval4 = aw4[rval4];
    var put4 = '<input type="text" id="num4" name="num4" ></input>';
    document.getElementById("p4").innerHTML = qval4 + " 答：";
    document.getElementById("p4").innerHTML += put4;

    var rval5 = Math.floor(Math.random() * (qu5.length));
    var qval5 = qu5[rval5];
    aval5 = aw5[rval5];
    var put5 = '<input type="text" id="num5" name="num5" ></input>';
    document.getElementById("p5").innerHTML = qval5 + " 答：";
    document.getElementById("p5").innerHTML += put5;

    var rval6 = Math.floor(Math.random() * (qu6.length));
    var qval6 = qu6[rval6];
    aval6 = aw6[rval6];
    var put6 = '<input type="text" id="num6" name="num6" ></input>';
    document.getElementById("p6").innerHTML = qval6 + " 答：";
    document.getElementById("p6").innerHTML += put6;

    var rval7 = Math.floor(Math.random() * (qu7.length));
    var qval7 = qu7[rval7];
    aval7 = aw7[rval7];
    var put7 = '<input type="text" id="num7" name="num7" ></input>';
    document.getElementById("p7").innerHTML = qval7 + " 答：";
    document.getElementById("p7").innerHTML += put7;

    var rval8 = Math.floor(Math.random() * (qu8.length));
    var qval8 = qu8[rval8];
    aval8 = aw8[rval8];
    var put8 = '<input type="text" id="num8" name="num8" ></input>';
    document.getElementById("p8").innerHTML = qval8 + " 答：";
    document.getElementById("p8").innerHTML += put8;

    var rval9 = Math.floor(Math.random() * (qu9.length));
    var qval9 = qu9[rval9];
    aval9 = aw9[rval9];
    var put9 = '<input type="text" id="num9" name="num9" ></input>';
    document.getElementById("p9").innerHTML = qval9 + " 答：";
    document.getElementById("p9").innerHTML += put9;

    var rval10 = Math.floor(Math.random() * (qu10.length));
    var qval10 = qu10[rval10];
    aval10 = aw10[rval10];
    var put10 = '<input type="text" id="num10" name="num10" ></input>';
    document.getElementById("p10").innerHTML = qval10 + " 答：";
    document.getElementById("p10").innerHTML += put10;
}

//随机生成计算的数
var answer1, answer2;
function shw() {
    var rnum1 = Math.random();
    var rnum2 = Math.random();
    var rnum3 = Math.random();
    var rnum4 = Math.random();
    var num1 = Math.floor(100 * rnum1);
    var num2 = Math.floor(100 * rnum2);
    var num3 = Math.floor(60 * rnum3);
    var num4 = Math.floor(60 * rnum4);
    answer1 = Number(num1) + Number(num2);
    answer2 = Number(num3) * Number(num4);
    var put1 = '<input type="text" id="num1" name="num1" ></input>';
    var put2 = '<input type="text" id="num2" name="num2"  ></input>';
    document.getElementById("p1").innerHTML = num1 + "+" + num2 + "=";
    document.getElementById("p2").innerHTML = num3 + "x" + num4 + "=";
    document.getElementById("p1").innerHTML += put1;
    document.getElementById("p2").innerHTML += put2;
    qn();
}

//开始答题按钮
var nam1;
function blink() {
    nam1 = document.getElementById("nam").value;
    var spac = nam1;
    spac = spac.replace(/\s/g, '');
    if (nam1 === null || nam1.length <= 0) {
        alert("请输入名字！");
        document.getElementById("nam").focus();
        return;
    }
    if (spac.length <= 0) {
        alert("名字不能为全空格！");
        document.getElementById("nam").focus();
        return;
    }
    //判断能否做题
    var val = rcook(nam1);
    if (val != null) {
        document.getElementById("to").innerHTML = nam1 + "&emsp;分数：" + val;
        //document.getElementById("bt1").disabled =true ;
        document.getElementById("bt2").disabled = true;
        return;
    } else {
        document.getElementById("to").innerHTML = "";
    }
    // document.getElementById("num1").disabled = false;
    // document.getElementById("num2").disabled = false;
    document.getElementById("bt1").disabled = true;
    document.getElementById("bt2").disabled = false;
    document.getElementById("mg").style.display = "";
    document.getElementById("na").style.display = "none"
    shw();
    document.getElementById("num1").focus();
    //document.getElementById("bt1").style.display="none";
    it = setInterval("clink()", 1000);
    // setTimeout("alink()",6000)

}